import javax.management.MBeanAttributeInfo;
import javax.print.StreamPrintService;
import javax.swing.*;
import java.sql.Array;
import java.sql.SQLOutput;
import java.util.Arrays;

public class shuzu {

    public static void main(String[] args) {
        //不规则二维矩阵
        int[][]hh = new int[3][];//可以省略列 但不能省略行
        //列可以更改
        hh[0] = new int[40];//将第一维数组的大小设置为4
        hh[1] = new int[3];//二维设置为3

        hh[0][39] = 20;
        hh[1][2] = 31;
        System.out.println(hh[2]);
        System.out.println(Arrays.deepToString(hh));
        System.out.println();
        System.out.println("======");
        System.out.println(hh[0][4]);
        System.out.println(hh[1][2]);
        System.out.println("======");
        //字符串拷贝Arrays.copyOf(
        int[] arr = new int[]{1, 2, 3, 4, 5};
        int[] arr1 = Arrays.copyOfRange(arr, 1, 4);//在一定范围内打印
        int[] atrr2 = Arrays.copyOf(arr,arr.length-1);//能决定atrr2有多大
        for (int x:arr1){
            System.out.print(x);
        }
        for (int x:atrr2
             ) {
            System.out.print(" " + x +" ");
        }
    }
    public static void main_erwei(String[] args) {
        //二维数组
        int[][] arr = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
        for (int[] x:arr
             ) {
            for (int y:x
                 ) {
                System.out.print(y + ' ' + " ");
                //System.out.printf("%d ",y);
            }
        }

    }
    public static void mainasd(String[] args) {
        int[] arr = new int[]{1, -2, 1, -5, 3, 4, 4, 3, 2, 1};
        Arrays.sort(arr);
        for (int x:arr
             ) {
            System.out.print(x+" ");
        }
        System.out.println(Arrays.binarySearch(arr,4));
    }
    public static boolean odd(int[] arr) {
        int str = 0;//记录第一个奇数位置
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] % 2 == 1) {
                count++;
            }
            if (arr[i] % 2 == 0) {
                count = 0;
            }
            if (count >= 3) {
                return true;
            }
        }
        return false;
    }

    public static void mainxx(String[] args) {
        int[] arr = new int[]{1, 30, 22, 33, 44, 55};
        boolean ed = odd(arr);
        System.out.println(ed);
    }

    public static int find_max(int[] arrays) {
        int count = 0;
        int[] sign = new int[500];//记录查找过的元素
        int sign_mark = 0;
        for (int i = 0; i < arrays.length; i++) {
            count = 0;
            int f = 0;//判断是否查找
            for (int j = 0; j < sign_mark; j++) {
                if (arrays[i] == sign[j]) {
                    f = 1;//不用查找
                    break;
                }
            }
            boolean once = true;//sign_mark在循环里面只加一次
            if (f == 0) {//找重复得元素
                for (int j = arrays[i]; j < arrays.length; j++) {
                    if (arrays[i] == arrays[j] && i != j) {
                        count++;
                        sign[sign_mark] = arrays[i];//记录查过的元素
                        if (once) {
                            sign_mark++;
                            once = false;
                        }
                    }
                }
                if (count > arrays.length / 2) {//判断次数是否够
                    return arrays[i];
                }
            }
        }
        return -1;
    }

    public static void mainwe(String[] args) {
        int[] arrays = new int[]{1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
        int ed = find_max(arrays);
        System.out.println(ed);
    }

    public static int sigle(int[] arrags) {
        for (int i = 0; i < arrags.length; i++) {
            int flag = 0;
            for (int j = 0; j < arrags.length; j++) {//找i对应得元素
                if (arrags[i] == arrags[j] && i != j) {
                    flag = 1;
                }
            }
            if (flag == 0) {
                return arrags[i];
            }
        }
        return -1;
    }

    public static void mainSS(String[] args) {
        int[] arrays = new int[]{1, 1, 2, 3, 3, 4, 4};
        int ed = sigle(arrays);
        System.out.println(ed);
    }

    public static int[] sum(int[] arrays, int target) {
        int[] ed = new int[2];
        for (int i = 0; i < arrays.length; i++) {
            for (int j = 0; j < arrays.length; j++) {
                if ((arrays[i] + arrays[j] == target) && (arrays[i] != arrays[j]) && i != j) {
                    ed[0] = arrays[i];
                    ed[1] = arrays[j];
                    return ed;
                }
            }
        }
        return ed;
    }

    public static void mmamain(String[] args) {
        int[] arrays = new int[]{0, 1, 2, 3, 33, 22, 4, 5, 6, 7, 8};
        int target = 24;
        int[] ed = sum(arrays, target);
        for (int x : ed
        ) {
            System.out.print(x + " ");
        }
    }

    public static void mmmain(String[] args) {
        //arrays = odd_head(arrays);
//        for (int x:arrays
//        ) {
//            System.out.println(x);
//        }
        int[] arrays = {71, 22, 33, 433, -4, 5252, -56};
        arrays = pop_sourt(arrays);
        for (int x : arrays
        ) {
            System.out.print(x + " ");
        }
        int ed = find_twohead(arrays, 71);
        System.out.println("\n下标为" + ed);
    }

    private static int[] pop_sourt(int[] arrays) {
        for (int i = 0; i < arrays.length; i++) {
            int flag = 0;
            for (int j = 0; j < arrays.length - 1 - i; j++) {
                if (arrays[j] > arrays[j + 1]) {
                    int tmp = arrays[j];
                    arrays[j] = arrays[j + 1];
                    arrays[j + 1] = tmp;
                    flag = 1;
                }
            }
            if (flag == 0) {
                break;
            }
        }
        return arrays;
    }

    public static int
    find_twohead(int[] arrags, int x) {
        int right = arrags.length, left = 0;
        while (right >= left) {
            int mid = (right + left) / 2;
            if (arrags[mid] > x) {
                right = mid;
                right--;
            } else if (arrags[mid] < x) {
                left = mid;
                left++;
            } else {
                return mid;
            }
        }
        return -1;
    }

    public static int[] odd_head(int[] arrays) {
        for (int i = 0; i < arrays.length; i++) {
            for (int j = 0; j < arrays.length - 1 - i; j++) {
                if (arrays[j] % 2 == 0) {
                    int f = arrays[j];
                    arrays[j] = arrays[j + 1];
                    arrays[j + 1] = f;
                }
            }
        }
        return arrays;
    }

    public static int[] twice(int[] haha) {//可以返回数组
        for (int i = 0; i < haha.length; i++) {
            haha[i] += haha[i];
        }
        return haha;

    }

    public static void mainaa(String[] args) {
        int[] haha = new int[]{1, 2, 3, 4, 5};
        haha = twice(haha);
        for (int x : haha
        ) {
            System.out.println(x);
        }
    }

    public static void mainh(String[] args) {
        //定义
        int[] one = new int[]{1, 2, 3, 4, 5};
        int[] two = {1, 2, 3, 4, 5};
        int[] three = new int[4];
        int[] four = three;
        int[] five;
        five = new int[]{2, 3, 4, 5};
        int[] six = null;
        //System.out.println(six[0]);//NullPointerException
        six = five;
        System.out.println(six);
        five = new int[]{1, 2, 3, 4};
        System.out.println(one);//可以理解打印得是one得地址，但是这个值其实是通过哈希算法装换过来的
        //不是真正的地址
        for (int i = 0; i < one.length; i++) {
            System.out.println(one[i]);
        }
        System.out.println();
        for (int x : one) {//将one里面得值取出来放在x中遍历
            System.out.println(x);
        }
    }

}

